import redis
from django.http import HttpResponse, JsonResponse
from django_redis import get_redis_connection
from redis.lock import Lock

import dadashop
from goods.models import SKU


def test_cors(request):
    return HttpResponse("OK")


r=get_redis_connection("default")
def test_stock(request):
    with Lock(r,"dadashop:test_stock",blocking_timeout=10):
    #测试redis分布式锁
        sku=SKU.objects.get(id=1)
        sku.stock-=1
        sku.save()

    return JsonResponse({'code':200,'msg':'OK'})